package com.wheat.vipcard.bean;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * Replytribune entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.wheat.vipcard.bean.Replytribune
 * @author MyEclipse Persistence Tools
 */

public class ReplytribuneDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(ReplytribuneDAO.class);
	// property constants
	public static final String TID = "tid";
	public static final String TTYPE = "ttype";
	public static final String RUSER_NAME = "ruserName";
	public static final String RUSER_ID = "ruserId";
	public static final String RCORRECT = "rcorrect";
	public static final String RTIME = "rtime";
	public static final String RGOOD = "rgood";
	public static final String RBAD = "rbad";

	public void save(Replytribune transientInstance) {
		log.debug("saving Replytribune instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Replytribune persistentInstance) {
		log.debug("deleting Replytribune instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Replytribune findById(java.lang.Integer id) {
		log.debug("getting Replytribune instance with id: " + id);
		try {
			Replytribune instance = (Replytribune) getSession().get(
					"com.wheat.vipcard.bean.Replytribune", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Replytribune instance) {
		log.debug("finding Replytribune instance by example");
		try {
			List results = getSession().createCriteria(
					"com.wheat.vipcard.bean.Replytribune").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Replytribune instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from Replytribune as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByTid(Object tid) {
		return findByProperty(TID, tid);
	}

	public List findByTtype(Object ttype) {
		return findByProperty(TTYPE, ttype);
	}

	public List findByRuserName(Object ruserName) {
		return findByProperty(RUSER_NAME, ruserName);
	}

	public List findByRuserId(Object ruserId) {
		return findByProperty(RUSER_ID, ruserId);
	}

	public List findByRcorrect(Object rcorrect) {
		return findByProperty(RCORRECT, rcorrect);
	}

	public List findByRtime(Object rtime) {
		return findByProperty(RTIME, rtime);
	}

	public List findByRgood(Object rgood) {
		return findByProperty(RGOOD, rgood);
	}

	public List findByRbad(Object rbad) {
		return findByProperty(RBAD, rbad);
	}

	public List findAll() {
		log.debug("finding all Replytribune instances");
		try {
			String queryString = "from Replytribune";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Replytribune merge(Replytribune detachedInstance) {
		log.debug("merging Replytribune instance");
		try {
			Replytribune result = (Replytribune) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Replytribune instance) {
		log.debug("attaching dirty Replytribune instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Replytribune instance) {
		log.debug("attaching clean Replytribune instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}